// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets;

import java.nio.ByteBuffer;
import zombie.characters.IsoPlayer;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.network.GameClient;
import zombie.network.NetworkVariables;

public class PlayerPacket implements INetworkPacket {
    public static final int PACKET_SIZE_BYTES = 43;
    public short id;
    public float x;
    public float y;
    public byte z;
    public float direction;
    public boolean usePathFinder;
    public NetworkVariables.PredictionTypes moveType;
    public short VehicleID;
    public short VehicleSeat;
    public int booleanVariables;
    public byte footstepSoundRadius;
    public byte bleedingLevel;
    public float realx;
    public float realy;
    public byte realz;
    public byte realdir;
    public int realt;
    public float collidePointX;
    public float collidePointY;
    public PlayerVariables variables = new PlayerVariables();

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        this.id = b.getShort();
        this.x = b.getFloat();
        this.y = b.getFloat();
        this.z = b.get();
        this.direction = b.getFloat();
        this.usePathFinder = b.get() == 1;
        this.moveType = NetworkVariables.PredictionTypes.fromByte(b.get());
        this.VehicleID = b.getShort();
        this.VehicleSeat = b.getShort();
        this.booleanVariables = b.getInt();
        this.footstepSoundRadius = b.get();
        this.bleedingLevel = b.get();
        this.realx = b.getFloat();
        this.realy = b.getFloat();
        this.realz = b.get();
        this.realdir = b.get();
        this.realt = b.getInt();
        this.collidePointX = b.getFloat();
        this.collidePointY = b.getFloat();
        this.variables.parse(b, connection);
    }

    @Override
    public void write(ByteBufferWriter b) {
        b.putShort(this.id);
        b.putFloat(this.x);
        b.putFloat(this.y);
        b.putByte(this.z);
        b.putFloat(this.direction);
        b.putBoolean(this.usePathFinder);
        b.putByte((byte)this.moveType.ordinal());
        b.putShort(this.VehicleID);
        b.putShort(this.VehicleSeat);
        b.putInt(this.booleanVariables);
        b.putByte(this.footstepSoundRadius);
        b.putByte(this.bleedingLevel);
        b.putFloat(this.realx);
        b.putFloat(this.realy);
        b.putByte(this.realz);
        b.putByte(this.realdir);
        b.putInt(this.realt);
        b.putFloat(this.collidePointX);
        b.putFloat(this.collidePointY);
        this.variables.write(b);
    }

    @Override
    public int getPacketSizeBytes() {
        return 43;
    }

    public boolean set(IsoPlayer chr) {
        if (GameClient.bClient) {
            this.id = (short)chr.getPlayerNum();
        } else {
            this.id = chr.OnlineID;
        }

        this.bleedingLevel = chr.bleedingLevel;
        this.variables.set(chr);
        return chr.networkAI.set(this);
    }

    public void copy(PlayerPacket packet) {
        this.id = packet.id;
        this.x = packet.x;
        this.y = packet.y;
        this.z = packet.z;
        this.direction = packet.direction;
        this.usePathFinder = packet.usePathFinder;
        this.moveType = packet.moveType;
        this.VehicleID = packet.VehicleID;
        this.VehicleSeat = packet.VehicleSeat;
        this.booleanVariables = packet.booleanVariables;
        this.footstepSoundRadius = packet.footstepSoundRadius;
        this.bleedingLevel = packet.bleedingLevel;
        this.realx = packet.realx;
        this.realy = packet.realy;
        this.realz = packet.realz;
        this.realdir = packet.realdir;
        this.realt = packet.realt;
        this.collidePointX = packet.collidePointX;
        this.collidePointY = packet.collidePointY;
        this.variables.copy(packet.variables);
    }

    public static class l_receive {
        public static PlayerPacket playerPacket = new PlayerPacket();
    }

    public static class l_send {
        public static PlayerPacket playerPacket = new PlayerPacket();
    }
}
